function upload_file(callback) {
  callback = callback || $.noop
  $('.pages a').live('click', function(){
    $('#files_container').load(this.href);
    return false;
  });

  $('a.file_delete').live('click', function(){
    var self = this;
    var id = this.href.substr(this.href.indexOf('#')+1);
    confirm('Are you sure to delete this?', function(){
      $.get(SITE_URL + "/admin/upload_file/delete/"+id+".html", function(){
        $(self).parent().parent().remove();
      });
    });

    return false;
  });

  $('<div title="My File Library"></div>')
  .append('<span id="file_pgb"></span>Uploading: <span id="file_name" class="fnt_dpblue"></span><div id="progressbar" style="height:10px;display:none" class="mt10 mb10"></div>')
  .append('<div id="files_search" class="clearfix mb10 mt10"><input type="text" class="input_text w290 fl" /><span class="btn fl"><a href="#">Search</a></span> <div style="width: 80px; margin-right: 20px" class="fr"><div id="spanButtonPlaceholder"></div></div></div>')
  .append('<table id="files_container" class="content_table" width="100%"></table>')
  .dialog({
  	width: 700,
  	height: 500,
  	modal: true,
  	buttons: {
  		"Insert": function() {
  		  var self = this;
  		  var id = $('input[name=select_file]:checked').val();
  		  if (id) {
  		    $.getJSON(SITE_URL + "/admin/upload_file/get/"+id+'.json', function(json){
    		    callback(json);
    		    $(self).dialog("close");
    		  });
  		  } else {
  		    alert('Please choose a file');
  		  }
  		},
  		"Cancel" : function() {
  		  $(this).dialog("close");
  		}
  	},
   close: function(event, ui) {
     $(this).remove();
   }
  });
  
  $('#files_search a').click(function(){
    var value = encodeURIComponent($('#files_search input').val());
    $('#files_container').load(SITE_URL + "/admin/upload_file/get_list/"+value+".html");
    
    return false;
  });



  $('#files_container').load(SITE_URL + "/admin/upload_file/get_list.html");
  
  var swfu = new SWFUpload({
      // Backend Settings
      upload_url: SITE_URL + "/admin/upload_file.html",   // Relative to the SWF file or absolute
      post_params: { "PHPSESSID": PHPSESSID },

      // File Upload Settings
      file_size_limit : "1000 MB",
      file_types : "*.*",
      file_types_description : "Select Files",
      file_upload_limit : "0",
      file_queue_limit  : "0",

      // Event Handler Settings - these functions as defined in Handlers.js
      //  The handlers are not part of SWFUpload but are part of my website and control how
      //  my website reacts to the SWFUpload events.
      file_queue_error_handler : function(file, errorCode, message) {
          switch (errorCode) {
          case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
              alert("upload erro");
              return;
          }
          alert('Upload failed, upload file cannot be larger than 1 GB');
      },

      upload_progress_handler : function(file, bytesLoaded, bytesTotal) {
        var percent = Math.ceil((bytesLoaded / bytesTotal) * 100);
        $('#file_pgb').show().html(percent+' %');
        $("#progressbar").show().progressbar({
    			value: percent
    		});
      },

      upload_start_handler : function(file) {
        $('#file_name').show().html(''+file.name);
        //alert(file.name);
      },
  
      file_dialog_complete_handler : function(numFilesSelected, numFilesQueued) {
          if (numFilesSelected > 0 && numFilesQueued > 0) {
              this.setButtonDisabled(true);
              this.startUpload();
          }
      },

      upload_error_handler : function (file, errorCode, message) {
          alert('upload failed : ' + message);
      },

      upload_success_handler : function(file, serverData) {
          // eval('var result = ' + serverData);
          // 
          // if (result.err == 0) {
          //     // 成功
          // } else {
          //     alert('上传失败!请稍后尝试');
          // }
          //alert(serverData);
          $('#files_container').load(SITE_URL + "/admin/upload_file/get_list.html");
          $("#progressbar,#file_pgb,#file_name").hide();
      },

      upload_complete_handler : function(file) {
          // console.log(this.getStats().files_queued);
          // alert(this.getStats().files_queued);
          if (this.getStats().files_queued > 0) {
              this.startUpload();
          } else {
              var $$ = this;
              $$.setButtonDisabled(false);
          }
      },
      // Button Settings
      button_placeholder_id : "spanButtonPlaceholder",
      button_image_url:       SITE_URL+"/images/add_file.png",
      // button_text : '<span class="button"></span>',
      // button_text_style : '.button { font-family: Helvetica, Arial, sans-serif; font-size: 12pt; font-color:red}',

      button_width: 91,
      button_height: 32,

      button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
      button_cursor: SWFUpload.CURSOR.HAND,

      // Flash Settings
      flash_url : SITE_URL+"/js/swfupload/swfupload.swf",

      // Debug Settings
      debug: false
  });
}
